<script>
// spy-debugger inject --- begin
(function () {
    if (window.spydebuggerDone) {
        return
    }
    try {
        window.spydebuggerDone = true;
        var showIframe = <%= showIframe %>;
        if (window.top === window.self || showIframe) {

            window.__spydebuggerPreLogList = [];
            var funcs = ['log', 'error', 'debug', 'info', 'warn'];
            for (var i = 0; i < funcs.length; i++) {
                var _real = console[funcs[i]];
                console[funcs[i]] = (function (m) {
                    return function functionName() {
                        __spydebuggerPreLogList.push({
                            m: m,
                            arg: arguments
                        })
                        try {
                            _real.apply(window.console, arguments);
                        } catch (e) {
                            
                        }
                    }
                })(funcs[i]);

            }

            document.write('<script src="//<%= weinreDomain %>/target/target-script-min.js#anonymous"><\/script>');

            var hasExec = false;
            var executeConsole = function () {
                if (hasExec) {
                    return;
                }
                hasExec = true;
                setTimeout(function () {
                    for (var i = 0; i < __spydebuggerPreLogList.length; i++) {
                        var o = __spydebuggerPreLogList[i];
                        var consoleforspydebugger = window.consoleforspydebugger;
                        consoleforspydebugger[o.m].apply(consoleforspydebugger, o.arg);
                    }
                }, 100);
            }

            document.addEventListener("DOMContentLoaded", executeConsole);
            window.addEventListener("load", executeConsole);

            if (<%= contentEditable %>) {
                var callBack = function () {
                    document.body.style.webkitUserSelect="auto";
                    document.body.style.webkitTouchCallout="default";
                    document.body.contentEditable=true;
                }
                var completed = function () {
                    document.removeEventListener("DOMContentLoaded", completed);
                    window.removeEventListener("load", completed);
                    callBack();
                }
                if (document.readyState === "complete" ||
                    (document.readyState !== "loading" && !document.documentElement.doScroll)) {
                    window.setTimeout(callBack);
                } else {
                    document.addEventListener("DOMContentLoaded", completed);
                    window.addEventListener("load", completed);
                }
            }
        } else {
            //do noting
        }

        window.onerror = function (message, url, lineNo, columnNo, errorObj) {
            console.error(message);
        }

    } catch (e) {
        console.error(e);
    }
})()

// spy-debugger inject --- end
</script>
